package com.nowc.week.w110;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class c {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int t =  Integer.parseInt(br.readLine());
        while (t-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
         String[] in = br.readLine().split(" ");
         int n = Integer.parseInt(in[0]);
         in = br.readLine().split(" ");
         long[] a = new long[n];
         for (int i = 0; i < n; i++) {
             a[i] = Long.parseLong(in[i]);
         }
         long ans = Long.MIN_VALUE;
         for (int i = 0; i < n - 1; i++) {
             int x;
             boolean has0 = (a[i] == 0 || a[i + 1] == 0);
             boolean has1 = (a[i] == 1 || a[i + 1] == 1);
             if (!has0) x = 0;
             else if (!has1) x = 1;
             else x = 2;
             ans = Math.max(Math.max(a[i], a[i + 1]) - x, ans);
         }
         out.println(ans);
    }
}
